<template>
  <div id="main1"></div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  props:['data'],
  data() {
    return {}
  },
  mounted() {
  },
  watch:{
    data({data,labels}){
      this.initEcharts(data,labels)
    }
  },
  methods:{
    initEcharts(data,labels){
      const newData  = data.map((item,index)=>({value:item,name:`${labels[index]}(${item})`}))
      const chartDom = document.getElementById('main1')
      const myChart = echarts.init(chartDom)
      let option
      option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          left: 'center',
          bottom: '10'
        },
        grid:{
          y:0
        },
        series: [
          {
            name: '',
            type: 'pie',
            radius: '50%',
            data: newData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      option && myChart.setOption(option);
    }
  }
}
</script>

<style scoped>
#main1 {
  width: 100%;
  height: 350px;
}
</style>
